package com.zzyl.serve.controller.member;

import com.fasterxml.jackson.annotation.JsonFormat;
import com.zzyl.common.core.domain.AjaxResult;
import com.zzyl.common.core.domain.R;
import com.zzyl.serve.dto.QueryDeviceDataListDto;
import com.zzyl.serve.dto.UserLoginRequestDto;
import com.zzyl.serve.service.IDeviceDataService;
import com.zzyl.serve.vo.DeviceDataGraphVo;
import com.zzyl.serve.vo.LoginVo;
import com.zzyl.serve.vo.WeekDateVo;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;
import com.zzyl.common.core.controller.BaseController;
import com.zzyl.serve.service.IFamilyMemberService;

import java.time.LocalDateTime;
import java.util.List;

/**
 * 老人家属Controller
 * 
 * @author itheima
 * @date 2025-03-12
 */
@RestController
@RequestMapping("/member/user")
@Api(tags = "老人家属相关接口")
public class FamilyMemberController extends BaseController
{
    @Autowired
    private IFamilyMemberService familyMemberService;




    /**
     * 小程序端 用户登录
     */
	@PostMapping("/login")
    @ApiOperation("小程序端 用户登录")
    public R<LoginVo> login(@RequestBody UserLoginRequestDto dto) {

        LoginVo vo = familyMemberService.login(dto);


        return R.ok(vo);
    }


    @Autowired
    private IDeviceDataService deviceDataService;
    /*
    * 接口地址:/member/user/queryDeviceDataListByWeek
      请求方式:GET*/
    @GetMapping("/queryDeviceDataListByWeek")
    @ApiOperation(" 按周统计查询指标数据")
    public R<List<WeekDateVo>> queryDeviceDataListByWeek(String iotId, String functionId,
                                                 Long startTime,
                                                Long endTime) {
      List<WeekDateVo> list = familyMemberService.queryDeviceDataListByWeek(iotId, functionId, startTime, endTime);
      return R.ok(list);
    }




     /*   QueryDeviceDataListVo queryDeviceDataListVo = familyMemberService.queryDeviceDataListByDay(functionId, startTime, endTime, iotId);
        return R.ok(queryDeviceDataListVo);
    }*/
    @GetMapping("queryDeviceDataListByDay")
    @ApiOperation("查询设备数据列表")
    public R<List<DeviceDataGraphVo>> queryDeviceDataListByDay(
            @ModelAttribute QueryDeviceDataListDto dto
    ) {
        // 验证参数是否为空
        if (dto.getFunctionId() == null || dto.getFunctionId().isEmpty()) {
            return R.fail("缺少必要的查询参数: functionId");
        }
        if (dto.getStartTime() == null) {
            return R.fail("缺少必要的查询参数: startTime");
        }
        if (dto.getEndTime() == null) {
            return R.fail("缺少必要的查询参数: endTime");
        }
        if (dto.getIotId() == null || dto.getIotId().isEmpty()) {
            return R.fail("缺少必要的查询参数: iotId");
        }

        List<DeviceDataGraphVo> list = familyMemberService.queryDeviceDataListByDay(dto);
        return R.ok(list);
    }

















}
